package com.zzh.demo;

import com.zzh.model.OrderBase;
import com.zzh.service.OrderService;
import com.zzh.utils.RabbitSendMessageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @PackageName:com.zzh.demo
 * @ClassName:RabbitMqPrudect
 * @Description:
 * @author:zhangzhanheng
 * @date: 2020/12/17 15:12
 */
@RestController
@RequestMapping("/rabbitMq")
@Slf4j
public class RabbitMqPrudect {


    @Autowired
    OrderService OrderService;

    @GetMapping("/send")
    public String send(@RequestParam(value = "message",required = false) String message) {
        String context = "Hello " + message + new Date();
//        String sendStr;
        OrderBase order = OrderBase.builder()
                .OrderNo("1111111")
                .orderName(message)
                .price(BigDecimal.valueOf(0.01))
                .build();
        order.setPrice(BigDecimal.valueOf(0.01));
        OrderService.createOrder(order);
//        for(int i=1;i<=100;i++){
//            sendStr="第["+i+"]个 hello  --" + new Date();
//            log.debug("HelloSender: " + sendStr);
//            rabbitSendMessageUtils.sendMessage("myqueue",sendStr);
//        }
        return context;
    }


}
